package org.hardstone.domain.media.resource;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import org.hardstone.domain.BaseItemDomain;
import org.hardstone.domain.BaseCategory;
import org.hardstone.domain.Status;

@Entity
@Table(name = "Music")
public class Music extends BaseItemDomain<Long> {

    @Column(name = "title")
    private String title;                   // 音乐标题

    @Column(name = "artist")
    private String artist;                  // 艺术家/乐队//

    @Column(name = "album")
    private String album;                   // 所属专辑

    @Column(name = "genre")
    private String genre;                   // 音乐风格/流派

    @Column(name = "releaseYear")
    private Integer releaseYear;            // 发行年份

    @Column(name = "duration")
    private Long duration;                  // 持续时长（毫秒）

    @Column(name = "bitrate")
    private Integer bitrate;                // 比特率（kbps）

    @Column(name = "fileFormat")
    private String fileFormat;              // 文件格式（MP3, WAV, FLAC等）

    @Column(name = "size")
    private Long size;                      // 文件大小（字节）

    @Column(name = "rating")
    private Float rating;                   // 用户评分

    @Column(name = "lyrics", columnDefinition = "TEXT")
    private String lyrics;                  // 歌词

    @Column(name = "composer")
    private String composer;                // 作曲家

    @Column(name = "recordLabel")
    private String recordLabel;             // 唱片公司

    @Column(name = "language")
    private String language;                // 歌曲语言

    public Music() {
    }

    public Music(Long id, Long itemGroupId, String name, BaseCategory category, Long userId, Long userGroupId, int authority, String url, String description, Status status, String askDate, String modifyDate, String tags, String attribute, String title, String artist, String album, String genre, Integer releaseYear, Long duration, Integer bitrate, String fileFormat, Long size, Float rating, String lyrics, String composer, String recordLabel, String language) {
        super(id, itemGroupId, name, category, userId, userGroupId, authority, url, description, status, askDate, modifyDate, tags, attribute);
        this.title = title;
        this.artist = artist;
        this.album = album;
        this.genre = genre;
        this.releaseYear = releaseYear;
        this.duration = duration;
        this.bitrate = bitrate;
        this.fileFormat = fileFormat;
        this.size = size;
        this.rating = rating;
        this.lyrics = lyrics;
        this.composer = composer;
        this.recordLabel = recordLabel;
        this.language = language;
    }

    // Getters and Setters for all fields
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getArtist() {
        return artist;
    }

    public void setArtist(String artist) {
        this.artist = artist;
    }

    public String getAlbum() {
        return album;
    }

    public void setAlbum(String album) {
        this.album = album;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public Integer getReleaseYear() {
        return releaseYear;
    }

    public void setReleaseYear(Integer releaseYear) {
        this.releaseYear = releaseYear;
    }

    public Long getDuration() {
        return duration;
    }

    public void setDuration(Long duration) {
        this.duration = duration;
    }

    public Integer getBitrate() {
        return bitrate;
    }

    public void setBitrate(Integer bitrate) {
        this.bitrate = bitrate;
    }

    public String getFileFormat() {
        return fileFormat;
    }

    public void setFileFormat(String fileFormat) {
        this.fileFormat = fileFormat;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }

    public Float getRating() {
        return rating;
    }

    public void setRating(Float rating) {
        this.rating = rating;
    }

    public String getLyrics() {
        return lyrics;
    }

    public void setLyrics(String lyrics) {
        this.lyrics = lyrics;
    }

    public String getComposer() {
        return composer;
    }

    public void setComposer(String composer) {
        this.composer = composer;
    }

    public String getRecordLabel() {
        return recordLabel;
    }

    public void setRecordLabel(String recordLabel) {
        this.recordLabel = recordLabel;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    // Advanced Methods
    public String getFormattedDuration() {
        long seconds = duration / 1000;
        long minutes = seconds / 60;
        seconds %= 60;
        return String.format("%d:%02d", minutes, seconds);
    }

    public String getPopularity() {
        if (rating >= 4.5) {
            return "Highly Popular";
        } else if (rating >= 3.5) {
            return "Popular";
        } else {
            return "Less Popular";
        }
    }

    public String getCategoryByYear() {
        if (releaseYear >= 2000) {
            return "Modern";
        } else if (releaseYear >= 1980) {
            return "Classic";
        } else {
            return "Vintage";
        }
    }

    @Override
    public String toString() {
        return "Music{" +
                "title='" + title + '\'' +
                ", artist='" + artist + '\'' +
                ", album='" + album + '\'' +
                ", genre='" + genre + '\'' +
                ", releaseYear=" + releaseYear +
                ", duration=" + duration +
                ", bitrate=" + bitrate +
                ", fileFormat='" + fileFormat + '\'' +
                ", size=" + size +
                ", rating=" + rating +
                ", lyrics='" + lyrics + '\'' +
                ", composer='" + composer + '\'' +
                ", recordLabel='" + recordLabel + '\'' +
                ", language='" + language + '\'' +
                ", formattedDuration='" + getFormattedDuration() + '\'' +
                ", popularity='" + getPopularity() + '\'' +
                ", categoryByYear='" + getCategoryByYear() + '\'' +
                '}';
    }
}
